package com.encyclopedia.controller;

import com.encyclopedia.entity.Family;
import com.encyclopedia.service.FamilyService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/plant/family")

public class FamilyController {
    @Autowired
    private FamilyService familyService;


    @GetMapping("/familyAll")
    public List<Family> familyAll() {
        return familyService.getFamilyAll();

    }

    @GetMapping("/familyOne")

    public Family familyOneByIdOrName(Family family) {
        return familyService.getFamilyOne(family);
    }

    @GetMapping("/familyByName")
    public List<Family> familyByName(@Param("familyName") String familyName) {
        return familyService.getFamilyByName(familyName);
    }

    //后续添加到admin中
    @PostMapping("/addFamily")
    public Integer addFamily(Family family) {
        return familyService.addFamily(family);
    }

    //后续添加带admin中
    @PostMapping("updateFamily")
    public Integer updateFamily(Family family) {
        return familyService.updateFamily(family);
    }


}
